﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="H2.NET.Web.Workflow.IncidentManage"
    CodeBehind="IncidentManage.aspx.cs" %>
<%@ Import Namespace="Ultimus.WFServer" %>
<%@ Register src="../UserControls/Pager.ascx" tagname="Pager" tagprefix="uc1" %>

<script type="text/javascript">

    function CancelIncidents() {
        var processNames = [];
        var incidentNoes = [];
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());
        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }
        });

        if (processNames.length == 0) {
            alertMsg.warn("至少选择一条流程");
            return false;
        }

        alertMsg.confirm("确定要取消所选的实例吗？", {
            okCall: function () {
                $.ajax({
                    type: "POST",
                    url: '<%=Page.ResolveUrl("~/Workflow/IncidentManage.aspx?action=cancel_incidents") %>',
                    data: { processNames: processNames.join(","), incidentNoes: incidentNoes.join(",") },
                    cache: false,
                    dataType: "json",
                    success: function (result) {
                        if (result == undefined || result.statusCode == 300) {
                            alertMsg.error("取消实例失败！");
                        }
                        else {
                            alertMsg.correct("成功：" + result.success + "条 失败：" + result.fail + "条");
                            navTab.reloadFlag("IncidentManage");
                        }
                    },
                    error: function (response) {
                        alert(response.success);
                    }
                });
            }
        });

        return false;
    }

    function FindAndReplaceVariables() {
        var processNames = [];
        var incidentNoes = [];
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());

        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }
        });

        if (processNames.length != 1) {
            alertMsg.warn("每次至少并且只能选择一条流程！");
            return false;
        }

        var title = processNames[0] + "(" + incidentNoes[0] + ") - 查找替换流程变量";
        $.pdialog.open("Workflow/FindAndReplaceVariables.aspx" + "?process=" + processNames[0] + "&incident=" + incidentNoes[0], "FindAndReplaceVariables", title, { width: 950, height: 600, mask: true });

        return false;
    }

    function RedirectStep() {
        var processNames = [];
        var incidentNoes = [];
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());

        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }
        });

        if (processNames.length != 1) {
            alertMsg.warn("每次至少并且只能选择一条流程！");
            return false;
        }

        var title = processNames[0] + "(" + incidentNoes[0] + ") - 激活或关闭步骤";
        $.pdialog.open("Workflow/RedirectStep.aspx" + "?process=" + processNames[0] + "&incident=" + incidentNoes[0], "RedirectStep", title, { width: 500, height: 350, mask: true });

        return false;
    }

    function AssignRecipient() {
        var processNames = [];
        var incidentNoes = [];
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());

        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }
        });

        if (processNames.length != 1) {
            alertMsg.warn("每次至少并且只能选择一条流程！");
            return false;
        }

        var title = processNames[0] + "(" + incidentNoes[0] + ") - 任务执行人指派";
        $.pdialog.open("Workflow/AssignRecipient.aspx" + "?process=" + processNames[0] + "&incident=" + incidentNoes[0], "AssignRecipient", title, { width: 800, height: 500, mask: true });

        return false;
    }



    function InitRecipient() {
        var processNames = [];
        var incidentNoes = [];
        var isMDC = false;
        var reason = $('#CancelReason').val();
        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());
        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }
            if ($(this).attr("processname").trim() == "Store Data Change" || $(this).attr("processname").trim() == "Store Deposit Receive" || $(this).attr("processname").trim() == "Store Deposit Change" || $(this).attr("processname").trim() == "New Store Application") {
                isMDC = true;
            }
        });

        if (processNames.length == 0) {
            alertMsg.warn("至少选择一条流程");
            return false;
        }

        if (reason == "" && isMDC == true) {
            alertMsg.warn("发现有MDC流程被取消实例，请填写原因。");
            return false;
        }

        alertMsg.confirm("确定要取消所选的实例吗？", {
            okCall: function () {
                $.ajax({
                    type: "POST",
                    url: '<%=Page.ResolveUrl("~/Workflow/IncidentManage.aspx?action=init_recipient") %>',
                    data: { processNames: processNames.join(","), incidentNoes: incidentNoes.join(","), abortreason: reason },
                    cache: false,
                    dataType: "json",
                    success: function (result) {
                        if (result == undefined || result.statusCode == 300) {
                            alertMsg.error("初始化失败！");
                        }
                        else {
                            alertMsg.correct("成功：" + result.success + "条 失败：" + result.fail + "条");
                            navTab.reloadFlag("IncidentManage");
                        }
                    },
                    error: function (response) {
                        alert(response.success);
                    }
                });
            }
        });

        return false;
    }

    function ChangeIncidentStatus() {
        var processNames = [];
        var incidentNoes = [];

        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());
        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                processNames.push($(this).attr("processname"));
                incidentNoes.push($(this).attr("incidentno"));
            }

        });

        if (processNames.length == 0) {
            alertMsg.warn("至少选择一条流程");
            return false;
        }



        $.pdialog.open("Workflow/ChangeIncidentStatus.aspx" + "?process=" + processNames.join(",") + "&incident=" + incidentNoes.join(","), "ChangeIncidentStatus", "流程实例状态管理", { width: 500, height: 200, mask: true });

        return false;
    }

    function checkShow() {
        var p;
        var isCheck;

        var $checkboxLi = $(":checkbox[name='ids']", navTab.getCurrentPanel() || $.pdialog.getCurrent());
        $checkboxLi.each(function () {
            if ($(this).attr("checked") == "checked") {
                p = ($(this).attr("processname"));
                if ((p.trim() == "Store Deposit Receive" || p.trim() == "Store Deposit Change" || p.trim() == "Store Data Change" || p.trim() == "New Store Application")) {
                    isCheck = true;
                }
            }
        });
        if (isCheck) {
            $("#cancel").fadeIn("slow");
        } else {
            $("#cancel").fadeOut();
        }


    }
</script>

<div class="pageHeader">
    <div class="searchBar">
    <form id="pagerForm" onsubmit="return navTabSearch(this);" action="<%= Page.ResolveUrl("~/Workflow/IncidentManage.aspx?read=1") %>" method="post">
        
        <input type="hidden" name="pageNum" value="<%= PageNumber %>" />
        <input type="hidden" name="numPerPage" value="<%= PageSize %>" />

        <table class="searchContent">
            <tr>
                <td>
                    <label>流程名：</label>
                    <select name="processName">
                        <option value="all">All</option>
                        <asp:repeater runat="server" ID="rptProcesses">
                             <ItemTemplate>
                                 <option value="<%# Eval("PROCESSNAME") %>"
                                 <%# Eval("PROCESSNAME").ToString().Trim() == (ProcessName ?? "").Trim()?"selected":"" %>><%# Eval("PROCESSNAME") %></option>
                             </ItemTemplate>
                        </asp:repeater>
                    </select>
                </td>
                <td>
                    <label>实例号：</label>
                    <input type="text" size="8" name="incidentNoFrom" value="<%:From %>"/> 至
                    <input type="text" size="8" name="incidentNoTo" value="<%:To %>" />
                </td>
                <td>
                    <label>摘要：</label>
                    <input type="text" name="summary" value="<%:Summary %>" />
                </td>
                <td>
                    <label><%= clsCmm.getTextValue("frm_initiate_gv_status")%></label>
                    <select name="status">
                        <option value="">All</option>
                        <option value="<%:IncidentStatuses.INCIDENT_STATUS_ACTIVE %>" <%:Status == IncidentStatuses.INCIDENT_STATUS_ACTIVE.ToString()?"selected":"" %>>Active</option>
                        <option value="<%:IncidentStatuses.INCIDENT_STATUS_ABORTED %>" <%:Status == IncidentStatuses.INCIDENT_STATUS_ABORTED.ToString()?"selected":"" %>>Aborted</option>
                        <option value="<%:IncidentStatuses.INCIDENT_STATUS_COMPLETED %>" <%:Status == IncidentStatuses.INCIDENT_STATUS_COMPLETED.ToString()?"selected":"" %>>Completed</option>
                        <option value="<%:IncidentStatuses.INCIDENT_STATUS_PENDING %>" <%:Status ==  IncidentStatuses.INCIDENT_STATUS_PENDING.ToString()?"selected":"" %>>Pending</option>
                    </select>
                </td>
            </tr>
        </table>
        <div class="subBar">
            <ul>
                <li>
                    <div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit">
                                <%=clsCmm.getTextValue("frm_inbox_btnSearch")%></button></div>
                    </div>
                </li>
            </ul>
        </div>
        </form>
    </div>
</div>

<form id="Form1" runat="server">
<div class="pageContent">
    <div class="panelBar">
        <ul class="toolBar">
            <li>
                <a class="cancel" href="javascript:void(0);" onclick="return CancelIncidents();">
                    <span><%=clsCmm.getTextValue("frm_inbox_btnCancel")%></span>
                </a>
            </li>
            <li>
                <a class="variables" href="javascript:void(0);" onclick="return FindAndReplaceVariables();">
                    <span>查找替换流程变量</span>
                </a>
            </li>
            <li>
                <a class="step" href="javascript:void(0);" onclick="return RedirectStep();">
                    <span>激活或关闭步骤</span>
                </a>
            </li>
            <li>
                <a class="status" href="javascript:void(0);" onclick="return ChangeIncidentStatus();">
                    <span>流程实例状态管理</span>
                </a>
            </li>
            <li>
                <a class="personalinfo" href="javascript:void(0);" onclick="return AssignRecipient();">
                    <span>任务执行人指派</span>
                </a>
            </li>
            <%--<li>
                <a class="assign" href="javascript:void(0);" onclick="return InitRecipient();">
                    <span>任务执行人初始化</span>
                </a>
            </li>--%>
        </ul>
    </div>
    <table class="formTable"  id="cancel" style="padding: 0px;width:100%;display: none">
            <tbody>
                <tr>
                    <th width="10%" >取消实例原因：</th>
                    <td width="90%"><input type="text" id="CancelReason" runat="server" style="width:90%"/></td>
                </tr>
            </tbody>
        </table>
    <table class="table" width="100%" layouth="137">
        <thead>
            <tr>
                <th width="22"></th>
                <th width="30">表单</th>
                <th width="200" align="center">流程名</th>
                <th width="60" align="center">实例号</th>
                <th>摘要</th>
                <th width="180" align="center">发起人</th>
                <th width="120" align="center">开始时间</th>
                <th width="120" align="center">结束时间</th>
                <th width="80" align="center">状态</th>
            </tr>
        </thead>
        <tbody>
            <asp:repeater id="gvInbox" runat="server">
                <ItemTemplate>
                    <tr style="height: 25px;line-height: 25px;">
                        <td><input name="ids" value="<%# Eval("taskid") %>" processname="<%# Eval("processname3").ToString().Trim()%>" incidentno="<%#Eval("incident")%>" type="checkbox" onclick="checkShow()"></td>
                        <td>
                                 
                            <a onclick="<%#Eval("processname3").ToString().Trim().Contains("Store Data Change")? "":Eval("processname3").ToString().Trim().Contains("Store Deposit Change")?"":Eval("processname3").ToString().Trim().Contains("Store Deposit Receive")?"":Eval("processname3").ToString().Trim().Contains("New Store Application")?"":"alert('只有SMD流程才能打开表单。');return false;"%>;return winOpenForm('<%# Eval("openform") %>?TaskID=<%# Eval("taskid") %>','tr_row_<%# Eval("taskid") %>');"><img alt="点击打开业务表单" border="0" src="Resource/Images/frm_inbox_open.gif" width="16" height="16"></a>
                           
                        </td>
                        <td><a href="workflow/monitor.aspx?TaskID=<%# Eval("taskid") %>" target="dialog" title="<%# Eval("processname3")%>[<%#Eval("incident")%>]&nbsp;-&nbsp;<%# Eval("summary")%>" width="1000" height="600" mask="true"><%# Eval("processname3") %></a></td>
                        <td><%#Eval("incident")%></td>
                        <td><%# Eval("summary")%></td>
                        <td><%# Eval("initiator")%></td>
                        <td><%# Eval("i_starttime","{0:yyyy-MM-dd HH:mm}")%></td>
                        <td><%# Eval("i_endtime","{0:yyyy-MM-dd HH:mm}")%></td>
                        <td><%# Eval("status_name") %></td>
                    </tr> 
                </ItemTemplate>
            </asp:repeater>
        </tbody>
    </table>
</div>
<uc1:Pager ID="Pager1" runat="server" />
</form>
